import { IAchievementWin } from "../interfaces/IAchievementWin";
import { AchievementConfig } from "../../../resource/AchievementConfig";
import { MuiEvent } from "../../../../../com/mui/events/MuiEvent";
import { AchievementDataProviderParser } from "../data/AchievementDataProviderParser";
import { SAchievementCategroy } from "../../../../../Message/Game/SAchievementCategroy";
import { SAchievementType } from "../../../../../Message/Game/SAchievementType";
import { Cache } from "../../../cache/Cache";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { AchievementProgressBar } from "../item/AchievementProgressBar";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { FontUtil } from "../../../../common/font/FontUtil";
import { AchievementCategorySubWin } from "./AchievementCategorySubWin";
import { AchievementOverViewSubWin } from "./AchievementOverViewSubWin";
import { GTabBar } from "../../../../../com/mui/controls/GTabBar";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { EffectManager } from "../../../manager/EffectManager";
type int = number;
//class AchievementDoingWin
    
    export  class AchievementDoingWin /* flash.display.Sprite */ implements IAchievementWin
    {
        constructor()
        {
            
            this.totalPoint = AchievementConfig.instance.getAchievmentTotalPoint();
            this.initView();
            this._achievmentTabBar.addEventListener(MuiEvent.GTABBAR_SELECTED_CHANGE, this.tabChangeHandler);
            return;
        }

        public updateShowingList(arg1: Array<any>): void
        {
            this._winCategory.visible = false;
            this._winOverView.visible = false;
            var loc1=new AchievementDataProviderParser().parse(arg1);
            if (arg1 && arg1[0] is SAchievementCategroy) 
            {
                this._winOverView.visible = true;
                this._winOverView.dataProvider = loc1;
            }
            else if (arg1 && arg1[0] is SAchievementType) 
            {
                this._winCategory.visible = true;
                this._winCategory.dataProvider = loc1;
            }
            else if (arg1 == null && !(loc1 == null)) 
            {
                this._winCategory.visible = true;
                this._winCategory.dataProvider = loc1;
            }
            return;
        }

        public updateLatestList(arg1: Array<any>): void
        {
            var loc1=new AchievementDataProviderParser().parseForRecentFinshedByCodes(arg1);
            this._winOverView.updateLatest(loc1);
            return;
        }

        public updateAchievementValue(arg1: int): void
        {
            this._progressBarLife.setValue(this.getAddLife(Cache.instance.role.money.prestige), this.getAddLife(this.totalPoint));
            this._progressBarYb.setValue(this.getYb(Cache.instance.role.money.prestige), this.getYb(this.totalPoint));
            this._txtAddLifePoint.text = arg1.toString();
            return;
        }

        public getCurTabIndex(): int
        {
            return this._achievmentTabBar.selectedIndex;
        }

        /* internal  */getAddLife(arg1: int): int
        {
            return int(arg1 * this.ConfigLift / this.ConfigChengJiu);
        }

        /* internal  */getYb(arg1: int): number
        {
            return int(arg1 * this.ConfigYb / this.ConfigChengJiu);
        }

        /* internal  */initView(): void
        {
            var loc1=null;
            var loc3=null;
            var loc7=null;
            ObjCreate.createBg(0, 0, 722, 62, this);
            loc1 = GlobalClass.getBitmap(ImagesConst.AchievementShengMingShangXian);
            loc1.x = 26;
            loc1.y = 7;
            this.addChild(loc1);
            this._progressBarLife = new AchievementProgressBar(ImagesConst.RedBar10);
            this._progressBarLife.x = 124;
            this._progressBarLife.y = 9;
            this.addChild(this._progressBarLife);
            loc1 = GlobalClass.getBitmap(ImagesConst.AchievementBindYuanBao);
            loc1.x = 26;
            loc1.y = 29;
            this.addChild(loc1);
            this._progressBarYb = new AchievementProgressBar(ImagesConst.YellowBar10);
            this._progressBarYb.x = 124;
            this._progressBarYb.y = 31;
            this.addChild(this._progressBarYb);
            var loc2=ObjCreate.createGTextField("", 301, 45, 200, 20, this);
            loc2.htmlText = Language.getStringByParam(80118, this.ConfigChengJiu, this.ConfigLift, this.ConfigYb);
            loc3 = GlobalClass.getBitmap(ImagesConst.AchievementChengjiu);
            loc3.x = 645;
            loc3.y = 4;
            this.addChild(loc3);
            var loc4;
            (loc4 = GlobalStyle.textFormatGreen).font = FontUtil.EmbedNumberName;
            loc4.size = 22;
            loc4.color = 10485504;
            loc4.align = flash.text.TextFormatAlign.CENTER;
            this._txtAddLifePoint = ObjCreate.createEmbedTextFiled("0", 637, 34, 60, 34, this, loc4);
            this._winCategory = new AchievementCategorySubWin();
            this.addChild(this._winCategory);
            this._winCategory.visible = false;
            this._winOverView = new AchievementOverViewSubWin();
            this.addChild(this._winOverView);
            this._achievmentTabBar = new GTabBar();
            this._achievmentTabBar.x = 7;
            this._achievmentTabBar.y = 69;
            this._achievmentTabBar.verticalGap = 6;
            this._achievmentTabBar.direction = GBoxDirection.VERTICAL;
            this._achievmentTabBar.buttonStyleName = "AchievementTabBtn";
            this._achievmentTabBar.buttonHeight = 34;
            this._achievmentTabBar.buttonWidth = 106;
            this._achievmentTabBar.dataProvider = this.AchievementDataProvider;
            this.addChild(this._achievmentTabBar);
            this._tabNames = new Object /* flash.display.Sprite */();
            this._tabNames.x = 20;
            this._tabNames.y = 82;
            this._tabNames.mouseChildren = false;
            this._tabNames.mouseEnabled = false;
            this.addChild(this._tabNames);
            var loc5=0;
            while (loc5 < this.TabNames.length) 
            {
                (loc7 = GlobalClass.getBitmap(String(this.TabNames[loc5]))).x = 0;
                loc7.y = loc5 * 40;
                this._tabNames.addChild(loc7);
                ++loc5;
            }
            var loc6;
            (loc6 = ResouceConst.getScaleBitmap(ImagesConst.VSpliteLine)).width = 1;
            loc6.height = 410;
            loc6.x = 122;
            loc6.y = 66;
            this.addChild(loc6);
            this.updateAchievementValue(Cache.instance.role.money.prestige);
            return;
        }

        /* internal  */tabChangeHandler(arg1: MuiEvent): void
        {
            if (this._achievmentTabBar.selectedIndex == this._preSelectedIndex) 
            {
                return;
            }
            if (this._achievmentTabBar.selectedIndex > (this.TabNum - 1)) 
            {
                this._achievmentTabBar.selectedIndex = this._preSelectedIndex;
                MsgManager.showRollTipsMsg(Language.getString(80067));
                return;
            }
            this._preSelectedIndex = this._achievmentTabBar.selectedIndex;
            Dispatcher.dispatchEvent(new DataEvent(EventName.AchievementClickTabar, {"index": this._achievmentTabBar.selectedIndex}));
            return;
        }

        public setTabSelected(arg1: int): void
        {
            if (arg1 < 0 || arg1 > (this.TabNum - 1)) 
            {
                return;
            }
            this._preSelectedIndex = arg1;
            this._achievmentTabBar.selectedIndex = arg1;
            return;
        }

        public updateTabFilters(arg1: Array<any>, arg2: Array<any>): void
        {
            var loc3=null;
            if (arg1 == null || arg2 == null) 
            {
                return;
            }
            var loc1=[FilterConst.achievementCanGetBonusFilter];
            var loc2=0;
            while (loc2 < this.TabNum) 
            {
                if ((loc3 = this._achievmentTabBar.getButtonAt(loc2)) != null) 
                {
                    if (arg1.indexOf(loc2) >= 0) 
                    {
                        EffectManager.glowFilterReg(loc3, loc1, 0.8, 10, 5, 0);
                    }
                    else 
                    {
                        EffectManager.glowFilterUnReg(loc3);
                    }
                }
                ++loc2;
            }
            return;
        }

        /* internal */ /* const */ConfigChengJiu: int=10;

        /* internal */ /* const */ConfigLift: int=50;

        /* internal */ /* const */ConfigYb: int=1;

        /* internal */ /* const */TabNum: int=8;

        /* internal */ /* const */AchievementDataProvider: Array<any>=[{"label":"", "name":"tab1"}, {"label":"", "name":"tab2"}, {"label":"", "name":"tab3"}, {"label":"", "name":"tab4"}, {"label":"", "name":"tab5"}, {"label":"", "name":"tab6"}, {"label":"", "name":"tab7"}, {"label":"", "name":"tab8"}];

        /* internal */ /* const */TabNames: Array<any>=[ImagesConst.AchievementCategoryOverView, ImagesConst.AchievementCategoryJuese, ImagesConst.AchievementCategoryZhuangbei, ImagesConst.AchievementCategoryShehui, ImagesConst.AchievementCategoryXianmeng, ImagesConst.AchievementCategoryPVP, ImagesConst.AchievementCategoryCaifu, ImagesConst.AchievementCategoryPVE];

        /* internal */ /* var */_achievmentTabBar: GTabBar;

        /* internal */ /* var */_preSelectedIndex: int=-1;

        /* internal */ /* var */_tabNames: Object /* flash.display.Sprite */;

        /* internal */ /* var */_winCategory: AchievementCategorySubWin;

        /* internal */ /* var */_winOverView: AchievementOverViewSubWin;

        /* internal */ /* var */_progressBarLife: AchievementProgressBar;

        /* internal */ /* var */_txtAddLifePoint: Object /* flash.text.TextField */;

        /* internal */ /* var */_progressBarYb: AchievementProgressBar;

        /* internal */ /* var */_txtAddYbPoint: Object /* flash.text.TextField */;

        /* internal */ /* var */totalPoint: int;
    }
